package com.dkts.oil.test.relrouter;

import com.graphhopper.GraphHopper;
import com.graphhopper.routing.Router;
import com.graphhopper.routing.RouterConfig;
import com.graphhopper.routing.WeightingFactory;
import com.graphhopper.routing.lm.LandmarkStorage;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.storage.BaseGraph;
import com.graphhopper.storage.RoutingCHGraph;
import com.graphhopper.storage.index.LocationIndex;
import com.graphhopper.util.TranslationMap;
import com.graphhopper.util.details.PathDetailsBuilderFactory;
import com.graphhopper.util.shapes.GHPoint;
import com.graphhopper.config.Profile;
import com.graphhopper.GraphHopperConfig;

import java.util.Map;

public class CustomGraphHopper extends GraphHopper {

    private final EncodingManager encodingManager;

    public CustomGraphHopper(EncodingManager encodingManager) {
        this.encodingManager = encodingManager;
    }

    /**
     * 覆写 getEncodingManager，避免 GraphHopper 内部调用时返回 null
     */
    @Override
    public EncodingManager getEncodingManager() {
        return encodingManager;
    }

    /**
     * 可选：覆写 doCreateRouter，使用自定义 EncodingManager
     */
    @Override
    protected Router doCreateRouter(BaseGraph baseGraph,
                                    EncodingManager encodingManager,
                                    LocationIndex locationIndex,
                                    Map<String, Profile> profilesByName,
                                    PathDetailsBuilderFactory pathBuilderFactory,
                                    TranslationMap trMap,
                                    RouterConfig routerConfig,
                                    WeightingFactory weightingFactory,
                                    Map<String, RoutingCHGraph> chGraphs,
                                    Map<String, LandmarkStorage> landmarks) {
        // 这里用自定义的 encodingManager 替代参数 encodingManager
        return new Router(baseGraph, this.encodingManager, locationIndex, profilesByName,
                pathBuilderFactory, trMap, routerConfig, weightingFactory, chGraphs, landmarks);
    }

    /**
     * 暴露设置 LocationIndex 的接口
     */
    public void setCustomLocationIndex(LocationIndex index) {
        this.setLocationIndex(index);
    }


}
